package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dto.PageSearchDTO;
import com.qf.entity.MallGoodsBrand;
import com.qf.entity.MallGoodsTemplate;
import com.qf.mapper.GoodsTemplateMapper;
import com.qf.service.IGoodsTemplateService;
import com.qf.vo.PageResult;
import com.qf.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>title: com.qf.service.impl</p>
 * <p>Company: wendao</p>
 * author zhuximing
 * date 2021/9/17
 * description:
 */
@Service
public class GoodsTemplateService implements IGoodsTemplateService {

   @Autowired
   private GoodsTemplateMapper goodsTemplateMapper;

    @Override
    public PageResult<MallGoodsTemplate> selectByPage(PageSearchDTO<MallGoodsTemplate> pageSearchDTO) {
        if (pageSearchDTO == null) {
            return  new PageResult<>(false, "参数不合法");
        }

        //设置分页信息
        PageHelper.startPage(pageSearchDTO.getPage(), pageSearchDTO.getSize());

        List<MallGoodsTemplate> byPage = goodsTemplateMapper.findByPage( pageSearchDTO.getWhere());

        //获取分页信息
        PageInfo<MallGoodsTemplate> pageInfo = new PageInfo<>(byPage);

        PageResult<MallGoodsTemplate> pageResult = new PageResult<>(true,"success");

        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setData(pageInfo.getList());



        return pageResult;
    }

    @Override
    public Result save(MallGoodsTemplate mallGoodsTemplate) {
        if (mallGoodsTemplate == null) {
            return  new Result(false, "参数不合法");
        }

        int save = goodsTemplateMapper.save(mallGoodsTemplate);

        return new Result(save==1?true:false, save==1?"success":"fail");
    }

    @Override
    public Result editTmp(MallGoodsTemplate mallGoodsTemplate) {
        if (mallGoodsTemplate == null) {
            return  new Result(false, "参数不合法");
        }

        int editTemp = goodsTemplateMapper.editTemp(mallGoodsTemplate);

        return new Result(editTemp==1?true:false, editTemp==1?"success":"fail");
    }

    @Override
    public Result delTmp(MallGoodsTemplate mallGoodsTemplate) {
        int delTemp = goodsTemplateMapper.delTemp(mallGoodsTemplate);

        return new Result(delTemp==1?true:false, delTemp==1?"success":"fail");
    }

}